﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text.RegularExpressions;
using System.Reflection;
using NUnit.Framework;

namespace Test
{
    [TestFixture]
    public class UnitTest1
    {
        [Test]
        [ExpectedException(ExpectedMessage = "Cannot use \"this\" in a lambda", MatchType = MessageMatch.StartsWith)]
        public void CannotUseThisInLambda()
        {
            TestFramework.TestCode("test", @"
namespace Blargh
{
    public class SomeClass
    {
        public int SomeField;
        public void SomeFunction()
        {
            Action a = () => Console.WriteLine(this.SomeField);
            a();
        }
    }
}", "");
        }

        [Test]
        [ExpectedException(ExpectedMessage = "C# 3.5 object initialization syntax is not supported", MatchType = MessageMatch.StartsWith)]
        public void ObjectInitilization()
        {
            TestFramework.TestCode("test", @"
namespace Blargh
{
    public static class Utilities
    {
        public static void SomeFunction()
        {
            var usingMe = new SomeUsingType()
            {
                Init1 = 0
            };
        }
    }
}", "");
        }

        [Test]
        public void UsingStatement()
        {

            TestFramework.TestCode(MethodInfo.GetCurrentMethod().Name, @"
using System;

namespace Blargh
{
    public static class Utilities
    {
        public static void SomeFunction()
        {
            var usingMe = new SomeUsingType();
            using (usingMe)
            {
                trace(""In using"");
            }
        }
    }
}", @"
package Blargh
{
    import System.*;
    import flash.utils.ByteArray;

    public final class Utilities
    {
        public static function SomeFunction():void
        {
            var usingMe:SomeUsingType = new SomeUsingType();
            try
            {
                trace(""In using"");
            }
            finally
            {
                usingMe.Dispose();
            }
        }
    }
}");
        }
        [Test]
        public void Math()
        {
            TestFramework.TestCode(MethodInfo.GetCurrentMethod().Name, @"
using System;

namespace Blargh
{
    public static class Utilities
    {
        public static void SomeFunction()
        {
            int i = 3;
            i += 4;
            i -= 3;
            ++i;
            i++;
            i--;
            --i;
            i *= 4;
            i %= 3;
            i = i + 1;
            i = i % 3;
            i = i - 4;
            i = i * 100;
            i = i / 3;
        }
    }
}", @"
package Blargh
{
    import System.*;
    import flash.utils.ByteArray;

    public final class Utilities
    {
        public static function SomeFunction():void
        {
            var i:int = 3;
            i += 4;
            i -= 3;
            ++i;
            i++;
            i--;
            --i;
            i *= 4;
            i %= 3;
            i = i + 1;
            i = i % 3;
            i = i - 4;
            i = i * 100;
            i = i / 3;
        }
    }
}");
        }

        [Test]
        public void Delegates()
        {
            TestFramework.TestCode(MethodInfo.GetCurrentMethod().Name, @"
using System;

namespace Blargh
{
    public delegate int NamespaceDlg();

    public static class Utilities
    {
        public delegate int GetMahNumber(int arg);

        public static void SomeFunction(GetMahNumber getit, NamespaceDlg getitnow)
        {
            trace(getit(getitnow()));
        }
    }
}", @"
package Blargh
{
    import System.*;
    import flash.utils.ByteArray;

    public final class Utilities
    {
        public static function SomeFunction(getit:Function, getitnow:Function):void
        {
            trace(getit(getitnow()));
        }
    }
}");
        }
     
        [Test]
        public void TypeStatics()
        {
            TestFramework.TestCode(MethodInfo.GetCurrentMethod().Name, @"
using System;

namespace Blargh
{
    public static class Utilities
    {
        public static void SomeFunction()
        {
            trace(int.MaxValue);
            trace(int.MinValue);
            string s = ""123"";
            trace(int.Parse(s) + 1);
        }
    }
}", @"
package Blargh
{
    import System.*;
    import flash.utils.ByteArray;

    public final class Utilities
    {
        public static function SomeFunction():void
        {
            trace(2147483647);
            trace(-2147483648);
            var s:String = ""123"";
	        trace(int(s) + 1);
        }
    }
}");
        }

        [Test]
        public void DictionaryAndHashSet()
        {
            TestFramework.TestCode(MethodInfo.GetCurrentMethod().Name, @"
using System;
using System.Collections.Generic;

namespace Blargh
{
    public static class Utilities
    {
        public static void SomeFunction()
        {
            Dictionary<int, int> dict = new Dictionary<int, int>();
            dict.Add(4, 3);
            trace(dict[4]);
            trace(dict.ContainsKey(8));
            dict.Remove(4);
            foreach(int key in dict.Keys)
                trace(key);
            foreach(int val in dict.Values)
                trace(val);
            
            HashSet<int> hash = new HashSet();
            hash.Add(999);
            trace(hash.Contains(999));
            hash.Remove(999);
            trace(hash.Contains(999));
            foreach(int hashItem in hash)
                trace(hashItem);
        }
    }
}", @"
package Blargh
{
    import System.*;
    import System.Collections.Generic.*;
    import flash.utils.ByteArray;

    public final class Utilities
    {
        public static function SomeFunction():void
        {
            var dict:CSDictionary = new CSDictionary();
            dict.Add(4, 3);
            trace(dict.GetValue(4));
            trace(dict.ContainsKey(8));
            dict.Remove(4);
            for each (var key:int in dict.Keys)
            {
                trace(key);
            }
            for each (var val:int in dict.Values)
            {
                trace(val);
            }
            
            var hash:HashSet = new HashSet();
            hash.Add(999);
            trace(hash.Contains(999));
            hash.Remove(999);
            trace(hash.Contains(999));
            for each (var hashItem:int in hash.Values())
            {
                trace(hashItem);
            }
        }
    }
}");
        }

        [Test]
        public void NullableTypes()
        {

            TestFramework.TestCode(MethodInfo.GetCurrentMethod().Name, @"
using System;

namespace Blargh
{
    public static class Utilities
    {
        public static void SomeFunction()
        {
            int? nullableInt = new Nullable<int>();
            trace(nullableInt.HasValue);
            int? withValue = new Nullable<int>(8);
            trace(withValue.Value);
        }
    }
}", @"
package Blargh
{
    import System.*;
    import flash.utils.ByteArray;

    public final class Utilities
    {
        public static function SomeFunction():void
        {
            var nullableInt:Nullable_int = new Nullable_int();
            trace(nullableInt.HasValue);
            var withValue:Nullable_int = new Nullable_int(8);
            trace(withValue.Value);
        }
    }
}");
        }

        [Test]
        public void TestEnum()
        {

            TestFramework.TestCode(MethodInfo.GetCurrentMethod().Name, @"
namespace Blargh
{
    public enum MostlyNumbered
    {
        One = 1,
        Two = 2,
        Three = 3,
        Unnumbered,
        SomethingElse = 50
    }
    public enum UnNumbered
    {
        One, Two, Three
    }
    class Clazz
    {
        public static void Methodz()
        {
            MostlyNumbered f = MostlyNumbered.One;
            UnNumbered[] arr = new UnNumbered[] { UnNumbered.One, UnNumbered.Two, UnNumbered.Three };
        }
    }
}", new string[] { @"
package Blargh
{
    import flash.utils.ByteArray;
    public final class MostlyNumbered
    {
        public static const One:int = 1;
        public static const Two:int = 2;
        public static const Three:int = 3;
        public static const Unnumbered:int = 4;
        public static const SomethingElse:int = 50;
    }
}", @"
package Blargh
{
    import flash.utils.ByteArray;
    public final class UnNumbered
    {
        public static const One:int = 1;
        public static const Two:int = 2;
        public static const Three:int = 3;
    }
}", @"
package Blargh
{
    import flash.utils.ByteArray;
    class Clazz
    {
        public static function Methodz():void
        {
            var f:int = MostlyNumbered.One;
            var arr:Array = [ UnNumbered.One, UnNumbered.Two, UnNumbered.Three ];
        }
    }
}
"});
        }
        [Test]
        public void SwitchStatement()
        {

            TestFramework.TestCode(MethodInfo.GetCurrentMethod().Name, @"
using System;

namespace Blargh
{
    public static class Utilities
    {
        public static void SomeFunction()
        {
            string s = ""Blah"";
            switch (s)
            {
                case ""NotMe"":
                case ""Box"": trace(4); break;
                case ""Blah"": trace(3); break;
                default: trace(2); break;
            }
        }
    }
}", @"
package Blargh
{
    import System.*;
    import flash.utils.ByteArray;

    public final class Utilities
    {
        public static function SomeFunction():void
        {
            var s:String = ""Blah"";
            switch (s)
            {
                case ""NotMe"":
                case ""Box"": 
                    trace(4); 
                    break;
                case ""Blah"": 
                    trace(3); 
                    break;
                default: 
                    trace(2); 
                    break;
            }

        }
    }
}");
        }
        [Test]
        public void Linq()
        {

            TestFramework.TestCode(MethodInfo.GetCurrentMethod().Name, @"
using System;
using System.Linq;

namespace Blargh
{
    public static class Utilities
    {
        public static void SomeFunction()
        {
            int[] e = new int[] { 0, 1, 2, 3 };
            trace(e.First());
            trace(e.FirstWhere(o => o == 1));
            trace(e.ElementAt(2));
            trace(e.Last());
            trace(e.Count());
            trace(e.Where(o => o > 0).Count() + 2);
            trace(e.CountWhere(o => true) + 2);

            Dictionary<int, int> dict = e.ToDictionary(o => o, o => 555);
            e.OfType<int>();
        }
    }
}", @"
package Blargh
{
    import System.*;
    import System.Linq.*;
    import flash.utils.ByteArray;

    public final class Utilities
    {
        public static function SomeFunction():void
        {
            var e:Array = [ 0, 1, 2, 3 ];
            trace(Linq.First(e));
            trace(Linq.FirstWhere(e, function (o:*):*
            {
                return o == 1;
            } ));
            trace(Linq.ElementAt(e, 2));
            trace(Linq.Last(e));
            trace(Linq.Count(e));
            trace(Linq.Count(Linq.Where(e, function (o:*):*
            {
                return o > 0;
            } )) + 2);
            trace(Linq.CountWhere(e, function (o:*):*
            {
                return true;
            } ) + 2);
            var dict:CSDictionary = Linq.ToDictionary(e, function (o:*):*
            {
                return o;
            } , function (o:*):*
            {
                return 555;
            } );

            Linq.OfType(e, ""int"");
        }
    }
}");
        }

        [Test]
        public void OverloadedMethods()
        {
            TestFramework.TestCode(MethodInfo.GetCurrentMethod().Name, @"
using System;

namespace Blargh
{
    public static class Utilities
    {
        public static void OverOne()
        {
            OverOne(3, ""Blah"");
        }

        public static void OverOne(int param)
        {
            OverOne(3, ""Blah"");
        }

        public static void OverOne(int param, string prm)
        {
            trace(param + prm);
        }

        public static int OverTwo(int prm)
        {
            return prm;
        }
        public static int OverTwo()
        {
            return OverTwo(18);
        }
    }
}", @"
package Blargh
{
    import System.*;
    import flash.utils.ByteArray;

    public final class Utilities
    {
        public static function OverOne(param:int = 3, prm:String = ""Blah""):void
        {
            trace(param + prm);
        }
        public static function OverTwo(prm:int = 18):int
        {
            return prm;
        }
    }
}");
        }


        [Test]
        public void IsAndAs()
        {

            TestFramework.TestCode(MethodInfo.GetCurrentMethod().Name, @"
using System;

namespace Blargh
{
    public static class Utilities
    {
        public static void SomeFunction()
        {
            string s = ""Blah"";
            var list = new List<int>();
            if (s is string)
                trace(""Yes"");
            if (list is List<int>)
                trace(""Yes"");

            object o = s;
            string sss = o as string;
            trace(sss);
        }
    }
}", @"
package Blargh
{
    import System.*;
    import flash.utils.ByteArray;

    public final class Utilities
    {
        public static function SomeFunction():void
        {
            var s:String = ""Blah"";
            var list:Array = new Array();
            if (s is String)
            {
                trace(""Yes"");
            }
            if (list is Array)
            {
                trace(""Yes"");
            }

            var o:Object = s;
            var sss:String = o as String;
            trace(sss);
        }
    }
}");
        }
        

        [Test]
        public void AbstractAndOverrides()
        {
            TestFramework.TestCode(MethodInfo.GetCurrentMethod().Name, @"
using System;

namespace Blargh
{
    abstract public class TopLevel
    {
        public abstract void AbstractMethod();
        public abstract string AbstractProperty { get; }

        public virtual void VirtualMethod()
        {
            trace(""TopLevel::VirtualMethod"");
        }
        public virtual string VirtualProperty
        {
            get
            {
                return ""TopLevel::VirtualProperty"";
            }
        }

        public override string ToString()
        {
            return string.Empty;
        }
    }

    public class Derived : TopLevel
    {
        public override void AbstractMethod()
        {
            trace(""Derived::AbstractMethod"");
        }

        public override string AbstractProperty
        {
            get { return ""Derived::AbstractProperty""; }
        }

        public override void VirtualMethod()
        {
            base.VirtualMethod();
            trace(""Derived::VirtualMethod"");
        }

        public override string VirtualProperty
        {
            get
            {
                return base.VirtualProperty + ""Derived:VirtualProperty"";
            }
        }
        public override string ToString()
        {
            return ""DerivedToString"";
        }
    }
}", new string[] {
      @"
package Blargh
{
    import System.*;
    import flash.utils.ByteArray;

    public class TopLevel
    {
        public function get AbstractProperty():String
        {
        	throw new Error(""Abstract item called"");
        }
        public function get VirtualProperty():String
        {
            return ""TopLevel::VirtualProperty"";
        }

        public function AbstractMethod():void
        {
        	throw new Error(""Abstract item called"");
        }
        public function VirtualMethod():void
        {
            trace(""TopLevel::VirtualMethod"");
        }
        public function toString():String
        {
            return """";
        }
    }
}",
    @"
package Blargh
{
    import System.*;
    import flash.utils.ByteArray;

	public class Derived extends TopLevel
    {
        override public function get AbstractProperty():String
        {
            return ""Derived::AbstractProperty"";
        }
        override public function get VirtualProperty():String
        {
            return super.VirtualProperty + ""Derived:VirtualProperty"";
        }

        override public function AbstractMethod():void
        {
            trace(""Derived::AbstractMethod"");
        }
        override public function VirtualMethod():void
        {
            super.VirtualMethod();
            trace(""Derived::VirtualMethod"");
        }
        override public function toString():String
        {
            return ""DerivedToString"";
        }
    }
}
"  });
        }


        [Test]
        public void FieldsAndProperties()
        {
            TestFramework.TestCode(MethodInfo.GetCurrentMethod().Name, @"
using System;

namespace Blargh
{
    public class Box
    {
        private float _width;
        public float Width
        {
            get { return _width; }
            set { _width = value; }
        }
        
        public bool IsRectangular = true;
        public char[] Characters = new char[] { 'a', 'b' };
        public static Bottle StaticField;
        public const int ConstInt = 24;
        public int MultipleOne, MultipleTwo;

        static Box()
        {
            StaticField = new Bottle();
        }
    }
}", @"
package Blargh
{
    import System.*;
    import flash.utils.ByteArray;

    public class Box
    {
        private var _width:Number;
        public var IsRectangular:Boolean = true;
        public var Characters:Array = [ 'a', 'b' ];
        public static var StaticField:Bottle;
        public static const ConstInt:int = 24;
        public var MultipleOne:int;
        public var MultipleTwo:int;

        public function get Width():Number
        {
            return _width;
        }
        public function set Width(value:Number):void
        {
            _width = value;
        }

        internal static function cctor():void
        {
            StaticField = new Bottle();
        }
    }
    Box.cctor();
}");
        }

        

        [Test]
        public void Interfaces()
        {
            TestFramework.TestCode(MethodInfo.GetCurrentMethod().Name, @"
using System;

namespace Blargh
{
    public interface ITesting
    {
        void Poke();
    }

    public class Pokable : ITesting
    {
        public void Poke()
        {
            trace(""Implementation"");
        }
    }
}",
  new string[] { @"
package Blargh
{
    import System.*;
    import flash.utils.ByteArray;

    public interface ITesting
    {
        function Poke():void;
    }
}",
  @"
package Blargh
{
    import System.*;
    import flash.utils.ByteArray;

    public class Pokable implements ITesting
    {
        public function Poke():void
        {
            trace(""Implementation"");
        }
    }
}"});
        }

        [Test]
        public void TryCatchFinally()
        {
            TestFramework.TestCode(MethodInfo.GetCurrentMethod().Name, @"
using System;

namespace Blargh
{
    public static class Utilities
    {
        public static void SomeFunction()
        {
            trace(""Before try"");
            try
            {
                trace(""In try"");
            }
            catch (Exception ex)
            {
                trace(""In catch"");
            }
            finally
            {
                trace(""In finally"");
            }

            try
            {
                trace(""Try without finally"");
            }
            catch (IOException ex)
            {
                trace(""In second catch"");
            }
        }
    }
}", @"
package Blargh
{
    import System.*;
    import flash.utils.ByteArray;

    public final class Utilities
    {
        public static function SomeFunction():void
        {
            trace(""Before try"");
            try
            {
                trace(""In try"");
            }
            catch (ex:Exception)
            {
                trace(""In catch"");
            }
            finally
            {
                trace(""In finally"");
            }
            try
            {
                trace(""Try without finally"");
            }
            catch (ex:IOException)
            {
                trace(""In second catch"");
            }
        }
    }
}");
        }

        

        [Test]
        public void Generics()
        {
            TestFramework.TestCode(MethodInfo.GetCurrentMethod().Name, @"
using System;

namespace Blargh
{
    public static class Utilities
    {
        public static Queue<T> ToQueue<T>(this IEnumerable<T> array)
        {
            var queue = new Queue<T>();
            foreach (T a in array)
                queue.Enqueue(a);
            return queue;
        }
    }
}", @"
package Blargh
{
    import System.*;
    import flash.utils.ByteArray;

    public final class Utilities
    {
        public static function ToQueue(array:Array):Array
        {
            var queue:Array = new Array();
            for each (var a:* in array)
            {
                queue.push(a);
            }
            return queue;
        }
    }
}");
        }

        [Test]
        public void Objects()
        {
            TestFramework.TestCode(MethodInfo.GetCurrentMethod().Name, @"
using System;

namespace Blargh
{
    public static class Utilities
    {
        public static void SomeFunction()
        {
            var queue = new Queue<int>(10);
            queue.Enqueue(4);
            queue.Enqueue(2);
            trace(queue.Dequeue());
            queue.Clear();
    
            var list = new List<string>(3);
            list.Add(3);
            list.AddRange(new string[] { 4, 5, 6 });
            list.RemoveAt(0);
            list.Insert(8, 4);

            var stack = new Stack<bool>();
            stack.Push(true);
            stack.Push(false);
            Math.Max(stack.Pop(), stack.Pop();
        }
    }
}", @"
package Blargh
{
    import System.*;
    import flash.utils.ByteArray;

    public final class Utilities
    {
        public static function SomeFunction():void
        {
            var queue:Array = new Array();
            queue.push(4);
            queue.push(2);
            trace(queue.shift());
            queue.splice(0, 2147483646);
    
            var list:Array = new Array();
            list.push(3);
            list.push([ 4, 5, 6 ]);
            list.splice(0, 1);
            list.splice(8, 0, 4);

            var stack:Array = new Array();
            stack.push(true);
            stack.push(false);
            Math.max(stack.pop(), stack.pop());
        }
    }
}");
        }

        [Test]
        public void Lambda()
        {
            TestFramework.TestCode(MethodInfo.GetCurrentMethod().Name, @"
using System;

namespace Blargh
{
    public static class Utilities
    {
        public static void SomeFunction()
        {
            Func<int, int> f1 = x => x + 5;
            trace(f1(3));
            Func<int, int> f2 = x => { return x + 5; };
            trace(f2(3));
        }
    }
}", @"
package Blargh
{
    import System.*;
    import flash.utils.ByteArray;

    public final class Utilities
    {
        public static function SomeFunction():void
        {
            var f1:Function = function (x:int):int 
            { 
                return x + 5; 
            } ;
            trace(f1(3));
            var f2:Function = function (x:int):int 
            { 
                return x + 5; 
            } ;
            trace(f2(3));
        }
    }
}");
        }

        [Test]
        public void Loops()
        {
            TestFramework.TestCode(MethodInfo.GetCurrentMethod().Name, @"
using System;

namespace Blargh
{
    public static class Utilities
    {
        public static void SomeFunction()
        {
            while (true)
            {
                trace(""hi"");
                break;
            }

            for (int i=0;i<50;i++)
                trace(i);

            do
            {
                trace(""Dowhile"");
            }
            while (false);
        }
    }
}", @"
package Blargh
{
    import System.*;
    import flash.utils.ByteArray;

    public final class Utilities
    {
        public static function SomeFunction():void
        {
            while (true)
            {
                trace(""hi"");
                break;
            }

            for (var i:int = 0; i < 50; i++)
            {
                trace(i);
            }
            do
            {
                trace(""Dowhile"");
            }
            while (false);
        }
    }
}");
        }

        [Test]
        public void ArrayAndForEach()
        {
            TestFramework.TestCode(MethodInfo.GetCurrentMethod().Name, @"
using System;

namespace Blargh
{
    public static class Utilities
    {
        public static void SomeFunction()
        {
            string[] ar = new string[] { 1, 2, 3 };

            foreach(int i in ar)
                trace(i);

            trace(ar[1]);
            trace(ar.Length);
        }
    }
}", @"
package Blargh
{
    import System.*;
    import flash.utils.ByteArray;

    public final class Utilities
    {
        public static function SomeFunction():void
        {
            var ar:Array = [ 1, 2, 3 ];
            for each (var i:int in ar)
            {
            	trace(i);
            }
            trace(ar[1]);
            trace(ar.length);
        }
    }
}");
        }

        [Test]
        public void PartialClasses()
        {
            TestFramework.TestCode(MethodInfo.GetCurrentMethod().Name, 

new string[] { @"
using System;

namespace Blargh
{
    public partial class Utilities
    {
        public void FunFromOne()
        {
            trace(""I'm in one!"");
        }
    }
}",
            
  @"
using System;

namespace Blargh
{
    public partial class Utilities
    {
        public void FunFromTwo()
        {
            trace(""I'm in Two!"");
        }
    }
}"
}, @"
package Blargh
{
    import System.*;
    import flash.utils.ByteArray;

    public class Utilities
    {
        public function FunFromOne():void
        {
            trace(""I'm in one!"");
        }
        public function FunFromTwo():void
        {
            trace(""I'm in Two!"");
        }
    }
}");
        }

        [Test]
        public void StringMethods()
        {

            TestFramework.TestCode(MethodInfo.GetCurrentMethod().Name, @"
using System;

namespace Blargh
{
    public static class Utilities
    {
        public static void SomeFunction(string s2)
        {
            string s = @""500"";
            trace(s.IndexOf(""0""));
            trace(s2.IndexOf(""0""));

            foreach(string s3 in new string[] { ""Hello"" })
                s3.Substring(4, 5);
        }
    }
}", @"
package Blargh
{
    import System.*;
    import flash.utils.ByteArray;

    public final class Utilities
    {
        public static function SomeFunction(s2:String):void
        {
            var s:String = ""500"";
            trace(s.indexOf(""0""));
            trace(s2.indexOf(""0""));

            for each (var s3:String in [ ""Hello"" ])
            {
                s3.substr(4, 5);
            }
        }
    }
}");
        }

        [Test]
        public void ExtensionMethod()
        {

            TestFramework.TestCode(MethodInfo.GetCurrentMethod().Name, @"
using System;

namespace Blargh
{
    public static class Utilities
    {
        public static void SomeFunction()
        {
            int i = -3;
            trace(""false "" + i.IsFour());
            i++;
            i += 6;
            bool b = i.IsFour();
            trace(""true "" + b);
            Blargh.Utilities.IsFour(5);
        }

        public static bool IsFour(this int i)
        {
            return i == 4;
        }
    }
}", @"
package Blargh
{
    import System.*;
    import flash.utils.ByteArray;

    public final class Utilities
    {
        public static function SomeFunction():void
        {
            var i:int = -3;
            trace(""false "" + Blargh.Utilities.IsFour(i));
            i++;
            i += 6;
            var b:Boolean = Blargh.Utilities.IsFour(i);
            trace(""true "" + b);
            Blargh.Utilities.IsFour(5);
        }

        public static function IsFour(i:int):Boolean
        {
            return i == 4;
        }
    }
}");
        }

        [Test]
        public void HelloWorld()
        {

            TestFramework.TestCode(MethodInfo.GetCurrentMethod().Name, @"
using System;

namespace Blargh
{
    public static class Utilities
    {
        public static void SomeFunction()
        {
            trace(""Hello, World!"");
        }
    }
}", @"
package Blargh
{
    import System.*;
    import flash.utils.ByteArray;

    public final class Utilities
    {
        public static function SomeFunction():void
        {
            trace(""Hello, World!"");
        }
    }
}");
        }
        [Test]
        public void IfStatement()
        {

            TestFramework.TestCode(MethodInfo.GetCurrentMethod().Name, @"
using System;

namespace Blargh
{
    public static class Utilities
    {
        public static void SomeFunction()
        {
            string notInitialized;
            int myNum = 0;
            notInitialized = ""InitMe!"";

            if (myNum > 4)
                myNum = 2;
            else if (notInitialized == ""asdf"")
                myNum = 1;
            else
                myNum = 999;

            trace(myNum == 999 ? ""One"" : ""Two"");
        }
    }
}", @"
package Blargh
{
    import System.*;
    import flash.utils.ByteArray;

    public final class Utilities
    {
        public static function SomeFunction():void
        {
            var notInitialized:String;
            var myNum:int = 0;
            notInitialized = ""InitMe!"";

            if (myNum > 4)
            {
                myNum = 2;
            }
            else if (notInitialized == ""asdf"")
            {
                myNum = 1;
            }
            else
            {
                myNum = 999;
            }

            trace(myNum == 999 ? ""One"" : ""Two"");
        }
    }
}");
        }
    }
}
